package com.huanbao.scheduled;

import com.huanbao.service.ScheduledTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: ZQ
 * @date: 2021-05-08-09:48
 */
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScheduledTask {

    private final ScheduledTaskService taskService;

    // 添加定时任务
    @Scheduled(cron = "0 30 23 * * ?")
    public void dailyInspect() {
        log.info("定时任务----------》每日巡检投放记录是否更新！");
        boolean b = false;
        //循环防止执行失败
        int count = 0;
        while (!b) {
            try {
                b = taskService.dailyInspect();
            } catch (Exception e) {
                log.error("每日巡检定时任务异常----------->",e);
            } finally {
                count++;
                if (count > 3){
                    b = true;
                }
            }
        }
    }
}
